import java.util.ArrayList;

public class Literal {

	private String name;
	private Atom[] argv;
	
	public Literal(String name, Atom[] argv) {
		this.setName(name);
		
		this.setArgv(new Atom[argv.length]);
		for (int i = 0; i < argv.length; i++) 
		{
			if (argv[i] != null)
				this.argv[i] = new Atom(argv[i].getVarname());
		}
	}
	
	public String getName() {
		return name;
	}
	
	public Atom[] getArgv() {
		return argv;
	}
	
	private void setName(String name) {
		this.name = name;
	}
	
	private void setArgv(Atom[] argv) {
		this.argv = argv;
	}
	
	@Override
	public boolean equals(Object o) {
		if(o.getClass() == this.getClass()) {
			Literal other = (Literal) o;
			if( other.getName().equals(this.getName())
					&& other.getArgv().length == this.getArgv().length )   
			{
				
				for (int i = 0; i < other.getArgv().length; i++) 
				{
					// This are jokers
					if (other.getArgv()[i].getVarname().matches("[A-D]") && other.getArgv()[i].getVarname().length() == 1)
					{
						continue;
					}
					if (this.getArgv()[i].getVarname().matches("[A-D]") && this.getArgv()[i].getVarname().length() == 1)
					{
						continue;
					}
					if(!other.getArgv()[i].equals(this.getArgv()[i]))
						return false;
				}
				return true;
			}
		}
		return false;
	}
	
	@Override
	public String toString() {
		String out = "";
		out += name + "(";
		for (int i = 0; i < argv.length; i++) {
			out += argv[i].toString();
			if(i < argv.length - 1)
				out += ",";
		}
		out += ")";
		return out;
	}
}
